package com.google.code.util;

import com.google.code.constant.ALIGN;

public class STRING {
	public static String Align(String str, int width, ALIGN align) {
		return Align(str, width, align, ' ');
	}

	public static String Align(String str, int width, ALIGN align, char fill) {
		if (str == null)
			str = "";

		int len = width - str.length();

		if (align == ALIGN.LEFT)
			return str + rptChar(fill, len);

		if (align == ALIGN.CENTER)
			return rptChar(fill, len / 2) + str + rptChar(fill, (len + 1) / 2);

		if (align == ALIGN.RIGHT)
			return rptChar(fill, len) + str;

		return RTE.STRING();
	}

	private static String rptChar(char c, int num) {
		if (num < 0)
			return RTE.STRING();

		String str = "";
		while (num-- > 0)
			str += c;
		return str;
	}
}
